import java.util.Scanner;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 邓大帅
 * Date: 2022-11-10
 * Time: 17:44
 */
public class GreatestCommonDivisor {
    public static void main(String[] args) {
        Scanner input = new Scanner(System.in);
        int a = input.nextInt();
        int b = input.nextInt();
        int c = 0;
        if (a < b) {
            c = a;
            a = b;
            b = c;
        }
        while (b != 0){
            c = b;
            b = a % b;
            a = c;
        }
        System.out.println(a);
    }
}
